#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Create by zhang
# Create on 2022/6/21 17:18
from domain.common.base_dto import BaseDTO
from domain.common.schema_item import SchemaItem
from domain.report.common.period_enum import PeriodEnum


class BasicInfoDTO(BaseDTO):
    def __init__(self):
        self.stock_id:int = None
        self.stock_code:str = None
        self.year:int = None
        self.period:PeriodEnum = None


        self.company_name = None
        self.chairman = None
        self.reg_address = None
        self.office_postCode = None
        self.website = None
        self.secretary_name = None
        self.secretary_phone = None
        self.secretary_mail = None
        self.holder_num:int = None
        self.bonusSharesNum_per10 = None
        self.dividend_per10 = None
        self.transfersNum_per10 = None


class BasicInfoSchema:
    schema = {
        "company_name": SchemaItem(name="company_name", title="公司法定中文名称", value_type=float, is_must=True),
        "chairman": SchemaItem(name="chairman", title="公司法定代表人", value_type=float, is_must=True),
        "reg_address": SchemaItem(name="reg_address", title="公司注册地址", value_type=float, is_must=True),
        "office_postCode": SchemaItem(name="office_postCode", title="公司办公地址邮政编码", value_type=float, is_must=True),
        "website": SchemaItem(name="website", title="公司国际互联网网址", value_type=float, is_must=True),
        "secretary_name": SchemaItem(name="secretary_name", title="公司董事会秘书姓名", value_type=float, is_must=True),
        "secretary_phone": SchemaItem(name="secretary_phone", title="公司董事会秘书电话", value_type=float, is_must=True),
        "secretary_mail": SchemaItem(name="secretary_mail", title="公司董事会秘书电子信箱", value_type=float, is_must=True),
        "holder_num": SchemaItem(name="holder_num", title="报告期末股东总数", value_type=float, is_must=True),
        "bonusSharesNum_per10": SchemaItem(name="bonusSharesNum_per10", title="每10股送红股数", value_type=float, is_must=True),
        "dividend_per10": SchemaItem(name="dividend_per10", title="每10股派息数（含税）", value_type=float, is_must=True),
        "transfersNum_per10": SchemaItem(name="transfersNum_per10", title="每10股转增数", value_type=float, is_must=True)
    }

    @classmethod
    def get_schema(cls, name:str):
        return cls.schema.get(name, None)

    @classmethod
    def set(cls, dto:BasicInfoDTO, name:str, value):
        schemaItem:SchemaItem = cls.get_schema(name)
        if schemaItem:
            if isinstance(value, schemaItem.value_type):
                dto.set(name, value)
                return True
            elif schemaItem.value_type == str:
                dto.set(name, str(value))
                return True
            elif schemaItem.value_type == float:
                dto.set(name, float(value))
                return True
            elif schemaItem.value_type == int:
                dto.set(name, int(value))
                return True
            elif schemaItem.value_type == PeriodEnum:
                value = int(value)
                if value in PeriodEnum.get_values():
                    dto.set(name, value)
                return True
        return False